load motor.mat;
XtestNorm = motorNormalize(Xtest);
XtrainNorm = motorNormalize(Xtrain);

figure (21);
scatter(XtrainNorm,Ytrain);
axis([-1 1 -150 100]);
hold on;
maxPower = 19;
numDataPoints = size(XtrainNorm,1);
for powerIndex=1:maxPower
    designMatrix = ones(numDataPoints,powerIndex+1);
    for rowDesign=1:numDataPoints
        for colDesign=2:powerIndex+1
            designMatrix(rowDesign,colDesign)=XtrainNorm(rowDesign,1).^(colDesign-1);
        end
    end
    parameterVector = (designMatrix' * designMatrix)\designMatrix' * Ytrain;
    
    
    Xgraph = linspace(-1,1,1000);
    Ygraph = zeros(size(Xgraph,1),1);
    
    Ygraph = Ygraph + parameterVector(1,1);
    for parameterVectorIndex=2:size(parameterVector,1)
        Ygraph = Ygraph + parameterVector(parameterVectorIndex,1)*Xgraph.^(parameterVectorIndex-1); 
    end
    figure(21)
    p = plot(Xgraph,Ygraph);
    red = rand*0.75;
    green = rand*0.75;
    blue = rand*0.75;
    
    set(p,'Color',[red green blue]);
    
end
hold off;

